package leedcode;

import java.util.Arrays;

public class q283 {
    public static void main(String[] args) {
        Solution283_2 solution283_2 = new Solution283_2();
        int[] arr = new int[]{2, 1, 0, 3, 12};
        solution283_2.moveZeroes(arr);
        System.out.println(Arrays.toString(arr));
    }
}

class Solution283 {
    public void moveZeroes(int[] nums) {
        int i = 0;
        int n = 0;
        while (i < nums.length) {
            if (nums[n] == 0) {
                for (int j = n; j < nums.length - 1; j++) {
                    nums[j] = nums[j + 1];
                }
                nums[nums.length - 1] = 0;
            } else {
                n++;
            }
            i++;
        }
    }
}

class Solution283_2 {
    public void moveZeroes(int[] nums) {
        int n = nums.length, left = 0, right = 0;
        while (right < n) {
            if (nums[right] != 0) {
                int temp = nums[left];
                nums[left] = nums[right];
                nums[right] = temp;
                left++;
            }
            right++;
        }
    }
}